layui.use(['jquery','form','element'], function(){
    var $ = layui.jquery;
    var form = layui.form();
    var element = layui.element();
    $.ajax({
        type: "GET",
        url: "/admin/project/getProject",
        dataType: "json",
        success: function (res) {
            var ops = '<option value="">--请选择--</option>';
            for (var project of res.data) {
                ops += '<option value="' + project.projectcode + '">' + project.projectname + '</option>';
            }
            $('#project').html(ops);
            form.render();
            form.on('select(Pfilter)',function() {
                var p = $('#project').val();
                alert(p)
                $.ajax({
                    type: "GET",
                    url: "/admin/building/getBuildingByPid",
                    data: {"pid": p},
                    dataType: "json",
                    success: function (res1) {
                        var ops1 = '<option value="">--请选择--</option>';
                        for (var building of res1.data) {
                            ops1 += '<option value="' + building.bCodes + '">' + building.bName + '</option>';
                        }
                        $('#building').html(ops1);
                        form.render();
                        form.on('select(Bfilter)',function() {
                            p = $('#building').val();
                            alert(p)
                            $.ajax({
                                type: "GET",
                                url: "/admin/Suite/getSuiteByBid",
                                data: {"bid": p},
                                dataType: "json",
                                success: function (res2) {
                                    var ops2 = '<option value="">--请选择--</option>';
                                    for (var suite of res2.data) {
                                        ops2 += '<option value="' + suite.roomnum + '">' + suite.roomnum + '</option>';
                                    }
                                    $('#suite').html(ops1);
                                    form.render();
                                    form.on('select(Sfilter)',function() {
                                        p = $('#suite').val();
                                        alert(p)
                                        $.ajax({
                                            type: "GET",
                                            url: "/admin/Room/getRoomBySid",
                                            data: {"sid": p},
                                            dataType: "json",
                                            success: function (res3) {
                                                var ops3 = '<option value="">--请选择--</option>';
                                                for (var city of res3.data) {
                                                    ops3 += '<option value="' + city.cid + '">' + city.cname + '</option>';
                                                }
                                                $('#room').html(ops1);
                                                form.render();
                                                form.on('select(Rfilter)',function() {
                                                    p = $('#room').val();
                                                    alert(p)
                                                    $.ajax({
                                                        type: "GET",
                                                        url: "/admin/Bunk/getBunkByRid",
                                                        data: {"Rid": p},
                                                        dataType: "json",
                                                        success: function (res4) {
                                                            var ops4 = '<option value="">--请选择--</option>';
                                                            for (var city of res4.data) {
                                                                ops4 += '<option value="' + city.cid + '">' + city.cname + '</option>';
                                                            }
                                                            $('#bunk').html(ops1);
                                                            form.render();

                                                        }
                                                    })
                                                })
                                            }
                                        })
                                    })
                                }
                            })
                        })
                    }
                })
            })
        }
    });
});